package org.beetl.spring.test;


import org.beetl.core.Context;
import org.beetl.core.Function;
import org.beetl.core.GroupTemplate;
import org.beetl.ext.spring6.BeetlTemplateCustomize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeetlGroupTemplateConfig {
    @Bean
    public BeetlTemplateCustomize beetlTemplateCustomize(){
        return new BeetlTemplateCustomize(){
            public void customize(GroupTemplate groupTemplate){
                groupTemplate.registerFunction("add", new Function() {
                    @Override
                    public Object call(Object[] paras, Context ctx) {
                        if(paras.length!=2){
                            throw new RuntimeException("参数错误，期望2个Int参数");
                        }
                        Number a = (Number)paras[0];
                        Number b = (Number)paras[1];
                        return a.intValue()+b.intValue();
                    }
                });

            }
        };
    }


}
